package com.hand.demo.infra.feign.fallback;

import com.hand.demo.infra.feign.MessageCodeFeign;
import com.hand.demo.infra.feign.MessageTypeFeign;
import org.hzero.boot.message.MessageClient;
import org.hzero.boot.message.entity.Receiver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

@RestController
public class MessageCodeFallBack {
    @Autowired
    MessageClient messageClient;
/*    @Resource
    MessageCodeFeign messageCodeFeign;
    @Resource
    MessageTypeFeign messageTypeFeign;*/

    @RequestMapping("/hmsg/v1/message/relevance/all")
    public void sendMessage(){
        long tenantId = 0L;
         // 消息发送配置编码
        String messageCode = "DEMO_MESSAGE_CODE";
        // 接收组编码
        String receiverGroupCode = "DEMO_RECEIVER";
        // 消息模板参数
        Map<String, String> args = new HashMap<>(2);
        args.put("param", "123456");
        messageClient.sendMessage(tenantId, messageCode, receiverGroupCode, args);
    }

    @RequestMapping("/hmsg/v1/message/relevance/Type")
    public void sendMessageByType(){
        long tenantId = 0L;
        // 消息发送配置编码
        String messageCode = "DEMO_MESSAGE_CODE";
        // 消息接收人信息（下面限制了只发送短信，接收人只需要指定国码和手机号即可）
        Receiver receiver = new Receiver().setIdd("+86").setPhone("130xxxxxxxx");
        List<Receiver> receiverList = Collections.singletonList(receiver);
        // 消息模板参数
        Map<String, String> args = new HashMap<>(2);
        args.put("param", "123456");
        // 限定允许发送的消息类型， WEB(站内信) EMAIL(邮件) SMS(短信)
        List<String> typeCodeList = new ArrayList<>();
        typeCodeList.add("SMS");
        messageClient.sendMessage(tenantId, messageCode, receiverList, args, typeCodeList);
    }
}
